<template>
	<view class="page-content">
		<view class="u-info-bg">
			<image src="/static/common/sun-bg.png" mode="" style="height: 417rpx;width: 100%;"></image>
		</view>
		<view class="content-box">
			<u-image width="100%" height="282rpx" :src="goods[0]&&goods[0].photo&&goods[0].photo.split(',')[0]"
				border-radius="48"></u-image>
			<view class="content-box-one">
				<view class="mt-16 flex-row justify-between items-center section_5">
					<view class="flex-col">
						<view class="flex-row items-center">
							<text class="font">我的光芒</text>
							<u-icon name="arrow-right"></u-icon>
						</view>
						<view class="mt-10 flex-row items-center">
							<image class="image_8" src="/static/common/sun.png" />
							<text class="text_3 ml-15">{{userinfo.integral||'0'}}</text>
						</view>
					</view>
					<view class="flex-row items-center button" @click="handleToGongLue">
						<text class="font_2 text_2">赚积分攻略</text>
						<u-icon name="arrow-right" size="24"></u-icon>
					</view>
				</view>
			</view>
			<view class="content-box-two">
				<u-subsection :list="list" :current="current" @change="handlechange" mode="subsection" height="64"
					active-color="#FCD610" bg-color="#FFFFFF" inactive-color="#000000"></u-subsection>
			</view>
			<view class="content-box-three">
				<view class="goods" v-if="current===0">
					<view class="good" v-for="(item,index) in goods" :key="index">
						<view class="good-img" @click="handleToDetail(item.id)">
							<u-image bg-color="#FFFFFF" width="100%" height="320rpx" :src="item.photo&&item.photo.split(',')[0]"
								border-radius="24"></u-image>
						</view>
						<view class="good-title">
							{{item.name}}
						</view>
						<view class="good-jifen flex-row items-center justify-center">
							<image src="/static/common/sun.png" style="height: 36rpx; width: 36rpx;"></image>
							{{item.needIntegral}}
						</view>
						<view class="good-buy" @click="handleSubmit(item.id)">
							立即兑换
						</view>
					</view>
				</view>
				<view class="buyed-goods" v-else>
					<view class="good" v-for="(item,index) in changelist" :key="index">
						<view class="mt-16 flex-col section_7">
							<view class="flex-row items-center self-stretch">
								<view class="flex-col justify-start items-center shrink-0">
									<u-image width="160rpx" height="160rpx" :src="item.photo&&item.photo.split(',')[0]"
										border-radius="24"></u-image>
								</view>
								<view class="flex-col flex-1 group_4 ml-13">
									<text class="font_3 text_6">{{item.productName}}</text>
									<view class="mt-18 flex-row justify-between items-center">
										<view class="flex-row items-center">
											<image class="shrink-0 image_10" src="/static/common/sun.png" />
											<text class="font text_7 ml-9">{{item.needIntegral}}</text>
										</view>
										<text class="text_8">×{{item.num}}</text>
									</view>
								</view>
							</view>
							<text class="self-start font_4 text_9">平台备注：</text>
							<view class="flex-col items-start self-stretch group_5">
								<text class="font_3">{{item.remark||''}}</text>
							</view>
							<view class="flex-row justify-between items-baseline self-stretch group_6">
								<text class="font_4">兑换日期</text>
								<text class="font_3 text_10">{{item.createTime}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import mine from '../../api/mine'
	import shopping from '../../api/shopping'
	export default {
		data() {
			return {
				list: [{
						name: '兑换商城'
					},
					{
						name: '已兑换'
					}
				],
				goods: [],
				changelist: [],
				current: 0,
				userinfo: null,
			}
		},
		onShow() {
			this.getDataList();
			const user = uni.getStorageSync("userinfo");
			if (user) {
				this.getUserInfo(user.id);
			}
		},
		methods: {
			handleToDetail(id) {
				uni.navigateTo({
					url: "/pages/sun/components/goods-detail/goods-detail?id=" + id
				})
			},
			getDataList() {
				shopping.getProductsList().then(res => {
					if (res.code == 200) {
						this.goods = res.rows;
					}
				})
			},
			getChangeList() {
				shopping.getChangeList().then(res => {
					if (res.code == 200) {
						this.changelist = res.rows;
					}
				})
			},
			handlechange(value) {
				this.current = value;
				if (value == 0) {
					this.getDataList();
				} else {
					this.getChangeList()
				}
			},
			handleSubmit(id) {
				uni.navigateTo({
					url: `/pages/sun/components/order/order?goodsId=${id}&num=1`
				})
			},
			getUserInfo(userid) {
				mine.getUserInfo(userid).then(res => {
					if (res.code == 200) {
						this.userinfo = res.data;
					}
				})
			},
			handleToGongLue() {
				uni.navigateTo({
					url: '/pages/sun/components/jifengonglue/jifengonglue'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-content {
		height: 100%;
		background-color: #F6F6F6;
		display: flex;
		flex-direction: column;
		overflow-y: auto;

		.content-box {
			padding: 0 40rpx;
			margin-top: -250rpx;

			&-one {
				.ml-15 {
					margin-left: 30rpx;
				}

				.section_5 {
					padding: 36rpx 32rpx;
					background-color: #ffd60040;
					border-radius: 16rpx;

					.font {
						font-size: 28rpx;
						font-weight: 700;
						color: #000000;
					}

					.image_7 {
						width: 10rpx;
						height: 18rpx;
					}

					.image_8 {
						width: 40rpx;
						height: 42rpx;
					}

					.text_3 {
						color: #000000;
						font-size: 40rpx;
					}

					.button {
						padding: 16rpx;
						background-color: #ffffff;
						border-radius: 8rpx;
						height: 58rpx;

						.font_2 {
							font-size: 24rpx;
							font-weight: 700;
							color: #000000;
						}

						.text_2 {
							line-height: 22.22rpx;
							font-weight: unset;
						}
					}
				}
			}

			&-two {
				background-color: #ffffff;
				border-radius: 48rpx;
				overflow: hidden;
				margin-top: 32rpx;
			}

			&-three {
				margin-top: 32rpx;

				.goods {
					display: grid;
					grid-template-columns: 1fr 1fr;
					gap: 22rpx 24rpx;
					margin-bottom: 24rpx;

					.good {
						width: 320rpx;

						&-title {
							font-weight: 500;
							font-size: 28rpx;
							color: #000000;
							margin-bottom: 16rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
						}

						&-buy {
							margin-top: 10rpx;
							width: 100%;
							height: 60rpx;
							background: #FCD610;
							border-radius: 24rpx 24rpx 24rpx 24rpx;
							font-weight: bold;
							font-size: 24rpx;
							color: #000000;
							text-align: center;
							line-height: 60rpx;
						}
					}
				}

				.buyed-goods {
					margin-bottom: 24rpx;

					.good {
						.ml-13 {
							margin-left: 26rpx;
						}

						.mt-3 {
							margin-top: 6rpx;
						}

						.ml-9 {
							margin-left: 18rpx;
						}

						.section_7 {
							padding: 32rpx 28rpx 40rpx 32rpx;
							background-color: #ffffff;
							border-radius: 16rpx;

							.group_4 {
								margin-right: 8rpx;

								.text_6 {
									color: #000000;
								}

								.image_10 {
									width: 31.5rpx;
									height: 31.5rpx;
								}

								.font {
									font-size: 28rpx;
									font-family: PingFang SC;
									line-height: 25.96rpx;
									font-weight: 700;
									color: #000000;
								}

								.text_7 {
									line-height: 20.78rpx;
								}

								.text_8 {
									color: #979797;
									font-size: 28rpx;
									font-family: PingFang SC;
									font-weight: 700;
									line-height: 20rpx;
								}
							}

							.font_4 {
								font-size: 28rpx;
								font-family: PingFang SC;
								line-height: 25.96rpx;
								color: #000000;
							}

							.text_9 {
								margin-left: 4rpx;
								margin-top: 40rpx;
								line-height: 26.04rpx;
							}

							.group_5 {
								margin-top: 20rpx;
							}

							.font_3 {
								font-size: 28rpx;
								font-family: PingFang SC;
								line-height: 34rpx;
								color: #979797;
							}

							.group_6 {
								margin-top: 28rpx;
								padding-left: 4rpx;

								.text_10 {
									line-height: 20.78rpx;
								}
							}
						}
					}
				}

			}
		}


		/deep/ .u-item-bg {
			border-radius: 48rpx !important;
			color: #000000 !important;
		}

		/deep/ .u-item-first {
			border-top-left-radius: 48rpx !important;
			border-bottom-left-radius: 48rpx !important;
			border: 0 !important;
		}

		/deep/ .u-item-last {
			border: 0 !important;
			border-top-right-radius: 48rpx !important;
			border-bottom-right-radius: 48rpx !important;
		}

		/deep/ .u-item-text {
			color: #000000 !important;
		}
	}
</style>